package com.hspedu.homework.homework3;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author 谷其昊
 * @version 1.0
 * @date 2022/4/19
 * @time 10:57
 */
public class Homework03 {
    public static void main(String[] args) {
        String url = "http://www.sohu.com:8080/abc/index.htm";
        String regexp = "([a-zA-Z]+)://([a-zA-Z.]+):(\\d+)[\\w-/]*/([\\w.]+)";
        Pattern compile = Pattern.compile(regexp);
        Matcher matcher = compile.matcher(url);
        if (matcher.matches()){
            System.out.println("匹配成功");
            System.out.println(matcher.group(1));
            System.out.println(matcher.group(2));
            System.out.println(matcher.group(3));
            System.out.println(matcher.group(4));
        }else{
            System.out.println("匹配失败");
        }
    }
}
